



#ifndef I2C_MODULE_INTERFACE_H_
#define I2C_MODULE_INTERFACE_H_

#include "lpc_data_type.h"

#define MAX_I2C_NUMB		2
#define MAX_SLAVADDR_NUM 	1
#define MAX_PACKG_LENGTH	100
#define MIN_PACKG_LENGTH	7
#define MAX_RXPACKAG_BUF	3

#define I2C_CHANNEL_IPMBL		0
#define  I2C_CHANNEL_LOCAL		1

#define I2C_CHANNEL_UARTIPMB 0xFF

/* macro define  */
#define EVENT_TXOK_MASK	0x01	//tx success
#define EVENT_TXNA_MASK	0x02	//tx no ack
#define EVENT_TXBY_MASK	0x04	//tx bus busy
#define EVENT_TXBE_MASK	0x08	//tx bus error
#define EVENT_RXOK_MASK	0x10	//rx success
#define EVENT_RXNA_MASK	0x20	//rx no ack
#define EVENT_RXBY_MASK	0x40	//rx bus busy
#define EVENT_RXBE_MASK	0x80	//rx bus error

#define STATUS_BUF_EMPT	0x01	//buf empty
#define STATUS_BUF_FULL	0x02	//buf full



#define I2C_CLOCK_100K	100000
#define I2C_CLOCK_400K	400000


/* data type and struct define */

typedef struct{
	LPC_INT8U DataValid;
	LPC_INT8U DataLen;
	LPC_INT8U DataBuf[MAX_PACKG_LENGTH];
}I2C_RXBUF;


typedef struct
{	
	LPC_INT8U	I2c_Addr;
	LPC_INT8U 	EventMask;
	LPC_INT8U	IsReady;
	LPC_INT8U	IsStarted;	
	LPC_INT32U  	ClockRate;		/* 100k or 400k */
	LPC_INT8U  	IsMonitor;

	void (* CallBack_Fun)(LPC_INT8U deviceId,LPC_INT8U eventInd);
	
	I2C_RXBUF * I2c_RxBuf[MAX_RXPACKAG_BUF];
	LPC_INT8U  	RxBuf_Number;
	LPC_INT8U  	RxBuf_WritPoint;
	LPC_INT8U  	RxBuf_ReadPoint;
	
	/* add others we wanted item. */
} I2C_INSTANCE;




/*********************  function define ************************/
int I2C_Config(LPC_INT8U ChanNum,LPC_INT8U RxBufNum,LPC_INT8U TOValue);
int I2C_RegClient(LPC_INT8U ChanNum,LPC_INT8U EventMask,void * I2C_CallBack,LPC_INT8U AdrLen,LPC_INT8U * AdrList);
int I2C_UnregClient(LPC_INT8U ChanNum,LPC_INT8U AdrLen,LPC_INT8U * AdrList);
int I2C_TxData(LPC_INT8U ChanNum,LPC_INT8U DataLen,void * DataBuf);
int I2C_TxDataEx(LPC_INT8U ChanNum,LPC_INT8U DataLen,void * DataBuf);
int I2C_RxData(LPC_INT8U ChanNum,LPC_INT8U MaxLen,void * DataBuf);
LPC_INT8U I2c_RxBuf_Read(LPC_INT8U deviceId,LPC_INT8U maxLen,void * data);
LPC_BOOL I2c_RxBuf_IsEmpty(LPC_INT8U deviceId);
LPC_BOOL I2c_RxBuf_IsFull(LPC_INT8U deviceId);
void I2c_CallBack_Handle(LPC_INT8U deviceId,LPC_INT8U eventInd);
int  I2c_Device_Read(LPC_INT8U ChanNum,LPC_INT8U *SendData,LPC_INT8U SendLen,LPC_INT8U *RecvData,LPC_INT8U RecvLen);
int I2C_GetStatus(LPC_INT8U ChanNum,LPC_INT8U * RxBufStatus,LPC_INT8U * TxBufStatus,LPC_INT8U * EventStatus);
LPC_STATUS I2c_RxHBuf_Read(LPC_INT8U deviceId);
void I2c_InterruptHandler(LPC_INT8U ChanNum);

#endif /* I2C_MODULE_INTERFACE_H_ */



